﻿using MoreThanAdequate.Domain;
using MoreThanAdequate.Domain.LOTRO;
using RestSharp;

namespace MoreThanAdequate.WebServices
{
    public class LotroAPI
    {
        private const string API_URL = "http://data.lotro.com/";
        private const string API_DEVELOPER_NAME = "astraldragon1988";
        private const string API_DEVELOPER_KEY = "01453e6b4413ce669ae1b87d6cd4b3a1";

        private const string API_METHOD_CHARACTER = "charactersheet";
        private const string API_METHOD_GUILD = "guildroster";

        public LotroCharacter GetCharacter(string characterName)
        {
            var client = new RestClient(API_URL);
            var request = new RestRequest("{Developer}/{APIKey}/{MethodName}/w/{WorldName}/c/{CharacterName}");

            request.AddUrlSegment("Developer", API_DEVELOPER_NAME);
            request.AddUrlSegment("APIKey", API_DEVELOPER_KEY);
            request.AddUrlSegment("MethodName", API_METHOD_CHARACTER);
            request.AddUrlSegment("WorldName", Constants.KIN_SERVER);
            request.AddUrlSegment("CharacterName", characterName);

            var response = client.Execute<LotroCharacter>(request);

            return response.Data;
        }

        public LotroGuild GetGuild(string guildName)
        {
            var client = new RestClient(API_URL);
            var request = new RestRequest("{Developer}/{APIKey}/{MethodName}/w/{WorldName}/g/{GuildName}");

            request.AddUrlSegment("Developer", API_DEVELOPER_NAME);
            request.AddUrlSegment("APIKey", API_DEVELOPER_KEY);
            request.AddUrlSegment("MethodName", API_METHOD_GUILD);
            request.AddUrlSegment("WorldName", Constants.KIN_SERVER);
            request.AddUrlSegment("GuildName", guildName);

            var response = client.Execute<LotroGuild>(request);

            return response.Data;
        }
    }
}
